USE [CIMS]
GO

/****** Object:  Table [dbo].[User]    Script Date: 4/3/2014 12:11:01 PM ******/
DROP TABLE [dbo].[User]
GO

/****** Object:  Table [dbo].[User]    Script Date: 4/3/2014 12:11:01 PM ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[User](
	[UserId] [int] IDENTITY(1,1) NOT NULL,
	[Username] [nvarchar](max) NOT NULL,
	[Password] [nvarchar](max) NOT NULL,
	[Fullname] [nvarchar](max) NULL,
	[Address] [nvarchar](max) NULL,
	[Add_datetime] [datetime] NULL,
	[Lastup_datetime] [datetime] NULL,
 CONSTRAINT [PK_User] PRIMARY KEY CLUSTERED 
(
	[UserId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO


USE [CIMS]
GO

ALTER TABLE [dbo].[Task] DROP CONSTRAINT [FK_Task_OrderItem1]
GO

ALTER TABLE [dbo].[Task] DROP CONSTRAINT [FK_Task_OrderItem]
GO

/****** Object:  Table [dbo].[Task]    Script Date: 4/3/2014 12:10:55 PM ******/
DROP TABLE [dbo].[Task]
GO

/****** Object:  Table [dbo].[Task]    Script Date: 4/3/2014 12:10:55 PM ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[Task](
	[TaskId] [int] IDENTITY(1,1) NOT NULL,
	[StaffId] [int] NOT NULL,
	[OrderId] [int] NOT NULL,
 CONSTRAINT [PK_Task] PRIMARY KEY CLUSTERED 
(
	[TaskId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

ALTER TABLE [dbo].[Task]  WITH CHECK ADD  CONSTRAINT [FK_Task_OrderItem] FOREIGN KEY([StaffId])
REFERENCES [dbo].[Staff] ([StaffId])
GO

ALTER TABLE [dbo].[Task] CHECK CONSTRAINT [FK_Task_OrderItem]
GO

ALTER TABLE [dbo].[Task]  WITH CHECK ADD  CONSTRAINT [FK_Task_OrderItem1] FOREIGN KEY([OrderId])
REFERENCES [dbo].[OrderItem] ([OrderId])
GO

ALTER TABLE [dbo].[Task] CHECK CONSTRAINT [FK_Task_OrderItem1]
GO


USE [CIMS]
GO

ALTER TABLE [dbo].[Staff] DROP CONSTRAINT [FK_Staff_User]
GO

/****** Object:  Table [dbo].[Staff]    Script Date: 4/3/2014 12:10:50 PM ******/
DROP TABLE [dbo].[Staff]
GO

/****** Object:  Table [dbo].[Staff]    Script Date: 4/3/2014 12:10:50 PM ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[Staff](
	[StaffId] [int] NOT NULL,
 CONSTRAINT [PK_Staff] PRIMARY KEY CLUSTERED 
(
	[StaffId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

ALTER TABLE [dbo].[Staff]  WITH CHECK ADD  CONSTRAINT [FK_Staff_User] FOREIGN KEY([StaffId])
REFERENCES [dbo].[User] ([UserId])
GO

ALTER TABLE [dbo].[Staff] CHECK CONSTRAINT [FK_Staff_User]
GO


USE [CIMS]
GO

ALTER TABLE [dbo].[Service] DROP CONSTRAINT [FK_Service_Item]
GO

/****** Object:  Table [dbo].[Service]    Script Date: 4/3/2014 12:10:46 PM ******/
DROP TABLE [dbo].[Service]
GO

/****** Object:  Table [dbo].[Service]    Script Date: 4/3/2014 12:10:46 PM ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[Service](
	[ServiceId] [int] NOT NULL,
 CONSTRAINT [PK_Service] PRIMARY KEY CLUSTERED 
(
	[ServiceId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

ALTER TABLE [dbo].[Service]  WITH CHECK ADD  CONSTRAINT [FK_Service_Item] FOREIGN KEY([ServiceId])
REFERENCES [dbo].[Item] ([ItemId])
GO

ALTER TABLE [dbo].[Service] CHECK CONSTRAINT [FK_Service_Item]
GO


USE [CIMS]
GO

ALTER TABLE [dbo].[Product] DROP CONSTRAINT [FK_Product_Item]
GO

/****** Object:  Table [dbo].[Product]    Script Date: 4/3/2014 12:10:41 PM ******/
DROP TABLE [dbo].[Product]
GO

/****** Object:  Table [dbo].[Product]    Script Date: 4/3/2014 12:10:41 PM ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[Product](
	[ProductId] [int] NOT NULL,
 CONSTRAINT [PK_Product] PRIMARY KEY CLUSTERED 
(
	[ProductId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

ALTER TABLE [dbo].[Product]  WITH CHECK ADD  CONSTRAINT [FK_Product_Item] FOREIGN KEY([ProductId])
REFERENCES [dbo].[Item] ([ItemId])
GO

ALTER TABLE [dbo].[Product] CHECK CONSTRAINT [FK_Product_Item]
GO


USE [CIMS]
GO

ALTER TABLE [dbo].[OrderItem] DROP CONSTRAINT [FK_OrderItem_Item]
GO

ALTER TABLE [dbo].[OrderItem] DROP CONSTRAINT [FK_OrderItem_Customer]
GO

/****** Object:  Table [dbo].[OrderItem]    Script Date: 4/3/2014 12:10:36 PM ******/
DROP TABLE [dbo].[OrderItem]
GO

/****** Object:  Table [dbo].[OrderItem]    Script Date: 4/3/2014 12:10:36 PM ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[OrderItem](
	[OrderId] [int] IDENTITY(1,1) NOT NULL,
	[CustomerId] [int] NOT NULL,
	[ItemId] [int] NOT NULL,
	[Quantity] [int] NOT NULL,
	[Price] [float] NOT NULL,
	[Date_start] [datetime] NULL,
	[Date_order] [datetime] NULL,
	[Comment] [nvarchar](max) NULL,
 CONSTRAINT [PK_OrderItem] PRIMARY KEY CLUSTERED 
(
	[OrderId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO

ALTER TABLE [dbo].[OrderItem]  WITH CHECK ADD  CONSTRAINT [FK_OrderItem_Customer] FOREIGN KEY([CustomerId])
REFERENCES [dbo].[Customer] ([CustomerId])
GO

ALTER TABLE [dbo].[OrderItem] CHECK CONSTRAINT [FK_OrderItem_Customer]
GO

ALTER TABLE [dbo].[OrderItem]  WITH CHECK ADD  CONSTRAINT [FK_OrderItem_Item] FOREIGN KEY([ItemId])
REFERENCES [dbo].[Item] ([ItemId])
GO

ALTER TABLE [dbo].[OrderItem] CHECK CONSTRAINT [FK_OrderItem_Item]
GO


USE [CIMS]
GO

ALTER TABLE [dbo].[ManagerStaff] DROP CONSTRAINT [FK_ManagerStaff_User]
GO

/****** Object:  Table [dbo].[ManagerStaff]    Script Date: 4/3/2014 12:10:31 PM ******/
DROP TABLE [dbo].[ManagerStaff]
GO

/****** Object:  Table [dbo].[ManagerStaff]    Script Date: 4/3/2014 12:10:31 PM ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[ManagerStaff](
	[ManagerId] [int] NOT NULL,
 CONSTRAINT [PK_ManagerStaff] PRIMARY KEY CLUSTERED 
(
	[ManagerId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

ALTER TABLE [dbo].[ManagerStaff]  WITH CHECK ADD  CONSTRAINT [FK_ManagerStaff_User] FOREIGN KEY([ManagerId])
REFERENCES [dbo].[User] ([UserId])
GO

ALTER TABLE [dbo].[ManagerStaff] CHECK CONSTRAINT [FK_ManagerStaff_User]
GO


USE [CIMS]
GO

ALTER TABLE [dbo].[Land] DROP CONSTRAINT [FK_Land_Item]
GO

/****** Object:  Table [dbo].[Land]    Script Date: 4/3/2014 12:10:26 PM ******/
DROP TABLE [dbo].[Land]
GO

/****** Object:  Table [dbo].[Land]    Script Date: 4/3/2014 12:10:26 PM ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[Land](
	[LandId] [int] IDENTITY(1,1) NOT NULL,
	[Area] [nvarchar](max) NULL,
	[ItemId] [int] NOT NULL,
	[Size] [int] NULL,
 CONSTRAINT [PK_Land] PRIMARY KEY CLUSTERED 
(
	[LandId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO

ALTER TABLE [dbo].[Land]  WITH CHECK ADD  CONSTRAINT [FK_Land_Item] FOREIGN KEY([ItemId])
REFERENCES [dbo].[Item] ([ItemId])
GO

ALTER TABLE [dbo].[Land] CHECK CONSTRAINT [FK_Land_Item]
GO


USE [CIMS]
GO

/****** Object:  Table [dbo].[Item]    Script Date: 4/3/2014 12:10:23 PM ******/
DROP TABLE [dbo].[Item]
GO

/****** Object:  Table [dbo].[Item]    Script Date: 4/3/2014 12:10:23 PM ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[Item](
	[ItemId] [int] IDENTITY(1,1) NOT NULL,
	[Name] [nvarchar](max) NULL,
	[Description] [nvarchar](max) NULL,
	[Image] [nvarchar](max) NULL,
	[Price] [float] NULL,
 CONSTRAINT [PK_Item] PRIMARY KEY CLUSTERED 
(
	[ItemId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO


USE [CIMS]
GO

ALTER TABLE [dbo].[GravePurchased] DROP CONSTRAINT [FK_GravePurchased_Land]
GO

/****** Object:  Table [dbo].[GravePurchased]    Script Date: 4/3/2014 12:10:18 PM ******/
DROP TABLE [dbo].[GravePurchased]
GO

/****** Object:  Table [dbo].[GravePurchased]    Script Date: 4/3/2014 12:10:18 PM ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[GravePurchased](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[LandId] [int] NOT NULL,
	[Lastname] [nvarchar](max) NULL,
	[Firstname] [nvarchar](max) NULL,
	[DOB] [datetime] NULL,
	[DOD] [datetime] NULL,
	[Age] [int] NULL,
	[Hometown] [nvarchar](max) NULL,
 CONSTRAINT [PK_GravePurchased] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO

ALTER TABLE [dbo].[GravePurchased]  WITH CHECK ADD  CONSTRAINT [FK_GravePurchased_Land] FOREIGN KEY([LandId])
REFERENCES [dbo].[Land] ([LandId])
GO

ALTER TABLE [dbo].[GravePurchased] CHECK CONSTRAINT [FK_GravePurchased_Land]
GO


USE [CIMS]
GO

/****** Object:  Table [dbo].[GraveCategories]    Script Date: 4/3/2014 12:10:13 PM ******/
DROP TABLE [dbo].[GraveCategories]
GO

/****** Object:  Table [dbo].[GraveCategories]    Script Date: 4/3/2014 12:10:13 PM ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[GraveCategories](
	[CatId] [int] IDENTITY(1,1) NOT NULL,
	[Name] [nvarchar](max) NULL,
	[Description] [nvarchar](max) NULL,
	[Size] [int] NULL,
 CONSTRAINT [PK_GraveCategories] PRIMARY KEY CLUSTERED 
(
	[CatId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO


USE [CIMS]
GO

ALTER TABLE [dbo].[Grave] DROP CONSTRAINT [FK_Grave_Item]
GO

ALTER TABLE [dbo].[Grave] DROP CONSTRAINT [FK_Grave_GraveCategories]
GO

/****** Object:  Table [dbo].[Grave]    Script Date: 4/3/2014 12:10:09 PM ******/
DROP TABLE [dbo].[Grave]
GO

/****** Object:  Table [dbo].[Grave]    Script Date: 4/3/2014 12:10:09 PM ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[Grave](
	[GraveId] [int] IDENTITY(1,1) NOT NULL,
	[CatId] [int] NOT NULL,
	[ItemId] [int] NOT NULL,
 CONSTRAINT [PK_Grave] PRIMARY KEY CLUSTERED 
(
	[GraveId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

ALTER TABLE [dbo].[Grave]  WITH CHECK ADD  CONSTRAINT [FK_Grave_GraveCategories] FOREIGN KEY([CatId])
REFERENCES [dbo].[GraveCategories] ([CatId])
GO

ALTER TABLE [dbo].[Grave] CHECK CONSTRAINT [FK_Grave_GraveCategories]
GO

ALTER TABLE [dbo].[Grave]  WITH CHECK ADD  CONSTRAINT [FK_Grave_Item] FOREIGN KEY([ItemId])
REFERENCES [dbo].[Item] ([ItemId])
GO

ALTER TABLE [dbo].[Grave] CHECK CONSTRAINT [FK_Grave_Item]
GO


USE [CIMS]
GO

ALTER TABLE [dbo].[AdminBackEnd] DROP CONSTRAINT [FK_AdminBackEnd_User]
GO

/****** Object:  Table [dbo].[AdminBackEnd]    Script Date: 4/3/2014 12:10:04 PM ******/
DROP TABLE [dbo].[AdminBackEnd]
GO

/****** Object:  Table [dbo].[AdminBackEnd]    Script Date: 4/3/2014 12:10:04 PM ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[AdminBackEnd](
	[AdminId] [int] NOT NULL,
 CONSTRAINT [PK_AdminBackEnd] PRIMARY KEY CLUSTERED 
(
	[AdminId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

ALTER TABLE [dbo].[AdminBackEnd]  WITH CHECK ADD  CONSTRAINT [FK_AdminBackEnd_User] FOREIGN KEY([AdminId])
REFERENCES [dbo].[User] ([UserId])
GO

ALTER TABLE [dbo].[AdminBackEnd] CHECK CONSTRAINT [FK_AdminBackEnd_User]
GO


USE [CIMS]
GO

/****** Object:  Table [dbo].[Customer]    Script Date: 4/3/2014 12:09:57 PM ******/
DROP TABLE [dbo].[Customer]
GO

/****** Object:  Table [dbo].[Customer]    Script Date: 4/3/2014 12:09:57 PM ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[Customer](
	[CustomerId] [int] IDENTITY(1,1) NOT NULL,
	[Username] [nvarchar](max) NOT NULL,
	[Password] [nvarchar](max) NOT NULL,
	[Fullname] [nvarchar](max) NULL,
	[Email] [nvarchar](max) NULL,
	[Phone] [nvarchar](max) NULL,
	[Address] [nvarchar](max) NULL,
 CONSTRAINT [PK_Customer] PRIMARY KEY CLUSTERED 
(
	[CustomerId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO


